﻿Imports DotNetNuke
Imports DotNetNuke.Entities.Modules.Actions
Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.Modules.AccordionTabs.Components

Public Class Settings
    Inherits AccordionTabsSettingsBase

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            If (Page.IsPostBack = False) Then
                LoadAccordionSettings()
                LoadTabSettings()
                LoadjShowOffSettings()
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Public Overrides Sub UpdateSettings()
        Try
            SaveAccordionSettings()
            SaveTabSettings()
            SavejShowOffSettings()
            MyBase.UpdateSettings()
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Protected Sub LoadAccordionSettings()
        Try
            If Settings.Contains("Accordion_CSSClass") = True Then
                txtAccordion_CSSClass.Text = Settings("Accordion_CSSClass")
            Else
                txtAccordion_CSSClass.Text = "AccordionTabs"
            End If
            If Settings.Contains("Accordion_TabHeader") = True Then
                txtAccordion_TabHeader.Text = Settings("Accordion_TabHeader")
            Else
                txtAccordion_TabHeader.Text = "dnnFormSectionHead"
            End If
            If Settings.Contains("Accordion_RegionToToggle") = True Then
                txtAccordion_RegionSelector.Text = Settings("Accordion_RegionToToggle")
            Else
                txtAccordion_RegionSelector.Text = "fieldset"
            End If
            If Settings.Contains("Accordion_ClickToToggleSelector") = True Then
                txtAccordion_ClickToToogleSelector.Text = Settings("Accordion_ClickToToggleSelector")
            Else
                txtAccordion_ClickToToogleSelector.Text = "a"
            End If
            If Settings.Contains("Accordion_HideTabsOnStartup") = True Then
                If LCase(CType(Settings("Accordion_HideTabsOnStartup"), String)) = "true" Then
                    chkAccordion_InitiallyHideTabs.Checked = True
                Else
                    chkAccordion_InitiallyHideTabs.Checked = False
                End If
            Else
                chkAccordion_InitiallyHideTabs.Checked = False
            End If
            If Settings.Contains("Accordion_CookieDays") = True Then
                txtAccordion_CookieDays.Text = Settings("Accordion_CookieDays")
            Else
                txtAccordion_CookieDays.Text = "0"
            End If
            If Settings.Contains("Accordion_CookieMilleseconds") = True Then
                txtAccordion_CookieMilleseconds.Text = Settings("Accordion_CookieMilleseconds").ToString
            Else
                txtAccordion_CookieMilleseconds.Text = "120000"
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Protected Sub SaveAccordionSettings()
        Try
            Dim objCurrentModule As ModuleController = New ModuleController
            If txtAccordion_CSSClass.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_CSSClass", txtAccordion_CSSClass.Text)
            End If
            If txtAccordion_TabHeader.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_TabHeader", txtAccordion_TabHeader.Text)
            End If
            If txtAccordion_RegionSelector.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_RegionToToggle", txtAccordion_RegionSelector.Text)
            End If
            If txtAccordion_ClickToToogleSelector.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_ClickToToggleSelector", txtAccordion_ClickToToogleSelector.Text)
            End If
            If txtAccordion_CookieDays.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_CookieDays", txtAccordion_CookieDays.Text)
            End If
            If txtAccordion_CookieMilleseconds.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_CookieMilleseconds", txtAccordion_CookieMilleseconds.Text)
            End If
            If chkAccordion_InitiallyHideTabs.Checked = True Then
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_HideTabsOnStartup", "true")
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Accordion_HideTabsOnStartup", "false")
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Protected Sub LoadTabSettings()
        Try
            If Settings.Contains("Tabs_CSSClass") = True Then
                txtTabs_CSSClass.Text = Settings("Tabs_CSSClass")
            Else
                txtTabs_CSSClass.Text = "dnnAdminTabNav"
            End If
            If Settings.Contains("Tabs_CookieDays") = True Then
                txtTabs_CookieDays.Text = Settings("Tabs_CookieDays")
            Else
                txtTabs_CookieDays.Text = "0"
            End If
            If Settings.Contains("Tabs_CookieMilleseconds") = True Then
                txtTabs_CookieMilleseconds.Text = Settings("Tabs_CookieMilleseconds").ToString
            Else
                txtTabs_CookieMilleseconds.Text = "120000"
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Protected Sub SaveTabSettings()
        Try
            Dim objCurrentModule As ModuleController = New ModuleController
            If txtTabs_CSSClass.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Tabs_CSSClass", txtTabs_CSSClass.Text)
            End If
            If txtTabs_CookieDays.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Tabs_CookieDays", txtTabs_CookieDays.Text)
            End If
            If txtTabs_CookieMilleseconds.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "Tabs_CookieMilleseconds", txtTabs_CookieMilleseconds.Text)
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Protected Sub LoadjShowOffSettings()
        Try
            If Settings.Contains("jShowOff_CSSClass") = True Then
                txtjShowOff_CSSClass.Text = Settings("jShowOff_CSSClass")
            Else
                txtjShowOff_CSSClass.Text = ""
            End If
            If Settings.Contains("jShowOff_animatePause") = True Then
                If LCase(CType(Settings("jShowOff_animatePause"), String)) = "true" Then
                    chkjShowOff_animatePause.Checked = True
                Else
                    chkjShowOff_animatePause.Checked = False
                End If
            Else
                chkjShowOff_animatePause.Checked = True
            End If
            If Settings.Contains("jShowOff_autoPlay") = True Then
                If LCase(CType(Settings("jShowOff_autoPlay"), String)) = "true" Then
                    chkjShowOff_autoPlay.Checked = True
                Else
                    chkjShowOff_autoPlay.Checked = False
                End If
            Else
                chkjShowOff_autoPlay.Checked = True
            End If
            If Settings.Contains("jShowOff_changeSpeed") = True Then
                txtjShowOff_changeSpeed.Text = Settings("jShowOff_changeSpeed")
            Else
                txtjShowOff_changeSpeed.Text = "600"
            End If
            If Settings.Contains("jShowOff_controls") = True Then
                If LCase(CType(Settings("jShowOff_controls"), String)) = "true" Then
                    chkjShowOff_controls.Checked = True
                Else
                    chkjShowOff_controls.Checked = False
                End If
            Else
                chkjShowOff_controls.Checked = True
            End If
            If Settings.Contains("jShowOff_controlText") = True Then
                txtjShowOff_controlText.Text = Settings("jShowOff_ControlText")
            Else
                txtjShowOff_controlText.Text = "{ play:'Play', pause:'Pause', previous:'Previous', next:'Next' }"
            End If
            If Settings.Contains("jShowOff_effect") = True Then
                Select Case Settings("jShowOff_effect")
                    Case "none"
                        ddljShowOff_effect.Items.Add("No Effect - Selected")
                        ddljShowOff_effect.Items.Add("Fade between Tabs")
                        ddljShowOff_effect.Items.Add("Slide to left between Tabs")
                        ddljShowOff_effect.SelectedIndex = 0
                    Case "fade"
                        ddljShowOff_effect.Items.Add("No Effect")
                        ddljShowOff_effect.Items.Add("Fade between Tabs - Selected")
                        ddljShowOff_effect.Items.Add("Slide to left between Tabs")
                        ddljShowOff_effect.SelectedIndex = 1
                    Case "slideLeft"
                        ddljShowOff_effect.Items.Add("No Effect")
                        ddljShowOff_effect.Items.Add("Fade between Tabs")
                        ddljShowOff_effect.Items.Add("Slide to left between Tabs - Selected")
                        ddljShowOff_effect.SelectedIndex = 2
                    Case Else
                        ddljShowOff_effect.Items.Add("No Effect - Selected")
                        ddljShowOff_effect.Items.Add("Fade between Tabs")
                        ddljShowOff_effect.Items.Add("Slide to left between Tabs")
                        ddljShowOff_effect.SelectedIndex = 0
                End Select
            Else
                ddljShowOff_effect.Items.Add("No Effect - Selected")
                ddljShowOff_effect.Items.Add("Fade between Tabs")
                ddljShowOff_effect.Items.Add("Slide to left between Tabs")
                ddljShowOff_effect.SelectedIndex = 0
            End If
            If Settings.Contains("jShowOff_hoverPause") = True Then
                If LCase(CType(Settings("jShowOff_hoverPause"), String)) = "true" Then
                    chkjShowOff_hoverPause.Checked = True
                Else
                    chkjShowOff_hoverPause.Checked = False
                End If
            Else
                chkjShowOff_hoverPause.Checked = True
            End If
            If Settings.Contains("jShowOff_links") = True Then
                If LCase(CType(Settings("jShowOff_links"), String)) = "true" Then
                    chkjShowOff_links.Checked = True
                Else
                    chkjShowOff_links.Checked = False
                End If
            Else
                chkjShowOff_links.Checked = True
            End If
            If Settings.Contains("jShowOff_speed") = True Then
                txtjShowOff_speed.Text = Settings("jShowOff_speed")
            Else
                txtjShowOff_speed.Text = "3000"
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

    Protected Sub SavejShowOffSettings()
        Try
            Dim objCurrentModule As ModuleController = New ModuleController
            If txtjShowOff_CSSClass.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_CSSClass", txtjShowOff_CSSClass.Text)
            End If
            If txtjShowOff_changeSpeed.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_changeSpeed", txtjShowOff_changeSpeed.Text)
            End If
            If txtjShowOff_speed.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_speed", txtjShowOff_speed.Text)
            End If
            If txtjShowOff_controlText.Text = "" Then
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_controlText", txtjShowOff_controlText.Text)
            End If
            If chkjShowOff_animatePause.Checked = True Then
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_animatePause", "true")
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_animatePause", "false")
            End If
            If chkjShowOff_autoPlay.Checked = True Then
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_autoPlay", "true")
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_autoPlay", "false")
            End If
            If chkjShowOff_hoverPause.Checked = True Then
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_hoverPause", "true")
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_hoverPause", "false")
            End If
            If chkjShowOff_controls.Checked = True Then
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_controls", "true")
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_controls", "false")
            End If
            If chkjShowOff_links.Checked = True Then
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_links", "true")
            Else
                objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_links", "false")
            End If
            If IsNothing(ddljShowOff_effect.SelectedItem) = True Then
            Else
                Select Case ddljShowOff_effect.SelectedItem.Text
                    Case "No Effect"
                        objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_effect", "none")
                    Case "No Effect - Selected"
                        objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_effect", "none")
                    Case "Fade between Tabs"
                        objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_effect", "fade")
                    Case "Fade between Tabs - Selected"
                        objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_effect", "fade")
                    Case "Slide to left between Tabs"
                        objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_effect", "slideLeft")
                    Case "Slide to left between Tabs - Selected"
                        objCurrentModule.UpdateTabModuleSetting(TabModuleId, "jShowOff_effect", "slideLeft")
                    Case Else
                End Select
            End If
        Catch exc As Exception
            ProcessModuleLoadException(Me, exc)
        End Try
    End Sub

End Class